package com.xiaoshuidi.cloud.module.system.controller.admin.apartment;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.framework.security.core.LoginUser;
import com.xiaoshuidi.cloud.module.system.controller.admin.apartment.vo.ApartmentListReqVO;
import com.xiaoshuidi.cloud.module.system.controller.admin.apartment.vo.ApartmentRespVO;
import com.xiaoshuidi.cloud.module.system.convert.apartment.ApartmentConvert;
import com.xiaoshuidi.cloud.module.system.convert.dept.DeptConvert;
import com.xiaoshuidi.cloud.module.system.dal.dataobject.apartment.ApartmentDO;
import com.xiaoshuidi.cloud.module.system.service.apartment.ApartmentService;
import com.xiaoshuidi.cloud.module.system.service.dept.DeptService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;
import static com.xiaoshuidi.cloud.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;

@Tag(name =  "管理后台 - 门店管理")
@RestController
@RequestMapping("/system/apartment")
@Validated
public class ApartmentController {

    @Resource
    private DeptService deptService;

    @Resource
    private ApartmentService apartmentService;

    @PostMapping ("/list")
    @Operation(summary = "获取门店列表")
    //@PreAuthorize("@ss.hasPermission('system:dept:query')")
    public CommonResult<PageResult<ApartmentRespVO>> listApartments(@RequestBody ApartmentListReqVO reqVO) {
        PageResult<ApartmentRespVO> apartmentList = apartmentService.getApartmentList(reqVO);
        return success(apartmentList);
    }


    @GetMapping ("/creat")
    @Operation(summary = "获取门店列表")
    //@PreAuthorize("@ss.hasPermission('system:dept:query')")
    public CommonResult<Boolean> creat(@RequestParam("apartmentId") Long apartmentId,
                                                           @RequestParam("apartmentName") String apartmentName) {
        apartmentService.createApartment(apartmentId,apartmentName);
        return success(true);
    }

    /**
     * 初始化门店配置
     */
    @GetMapping ("/initialization")
    @Operation(summary = "初始化门店配置")
    //@PreAuthorize("@ss.hasPermission('system:dept:query')")
    public CommonResult<Boolean> initialization() {
        apartmentService.initialization();
        return success(true);
    }
}